package com.learn.normalClass;

import org.junit.Test;

public class StringTest {
    /**
     * String实例化
     */
    @Test
    public void test(){
        //通过字面量定义：s1和s2的数据声明在方法区中的字符串常量池中。
        String s1 = "JavaSE";
        String s2 = "JavaSE";

        //通过new+构造器的方法：s3和s4保存到地址值是数据在堆空间开辟空间以后对应的地址值。
        String s3 = new String("JavaSE");
        String s4 = new String("JavaSE");

        System.out.println(s1 == s2);//True
        System.out.println(s1 == s3);//false
        System.out.println(s3 == s4);//false
    }

    @Test
    public void test2(){
        String s1 = "java";
        String s2 = "hadoop";
        String s3 = "javahadoop";
        String s4 = "java" + "hadoop";
        String s5 = s1 + "hadoop";
        String s6 = "java" + s2;
        String s7 = s1 + s2;

        System.out.println(s3 == s4);//true
        System.out.println(s3 == s5);//false
        System.out.println(s3 == s6);//false
        System.out.println(s5 == s6);//false
        System.out.println(s3 == s7);//false
        System.out.println(s6 == s7);//false
    }
}
